var ns, app, dialog, toast;
app = new Vue({
    el: '#app',
    data: {
        ID: 0,
        RoomName: '',
        form: {},
        ServiceList: [],//会议服务
        TotalPrice: 0,
        ItemList: [],//临时物品
    },
    methods: {
        get_data: function () {
            var that = this;
            var options = {
                action: 'getmeetingreservationinfo',
                ID: that.ID,
            };
            ns.post(options, function (succeed, data, err) {
                if (succeed) {
                    that.RoomName = data.newServiceList;
                    that.form = data.MeetingReservationInfo;
                    if (that.form.CreateTime) {
                        that.form.CreateTime = moment(that.form.CreateTime).format("YYYY-MM-DD HH:mm:ss");
                    }
                    if (that.form.ReservationDate) {
                        that.form.ReservationDate = moment(that.form.ReservationDate).format("YYYY-MM-DD");
                    }
                    that.ServiceList = data.ServiceList;
                    that.ItemList = data.ItemList;
                    that.TotalPrice = 0;
                    if (that.ServiceList.length > 0) {
                        var countPrice = 0;
                        that.ServiceList.forEach((item, index, array) => {
                            countPrice += item.Number * item.UnitPrice;
                        });
                        that.TotalPrice = countPrice.toFixed(2);
                    }
                }
                else {
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                    return;
                }
            }, {
                toast: true
            });
        },
        //结束会议
        doMeetEnd() {
            var that = this;
            api.confirm({
                title: '提示',
                msg: '确定要手动结束会议吗?',
                buttons: ['确定', '取消']
            }, function (ret, err) {
                if (ret.buttonIndex == 1) {
                    ///调用接口
                    var options = {};
                    options.action = 'changemeetingreservation';
                    options.ID = that.ID;
                    options.ChangeType = 'endMeeting';
                    ns.post(options, function (succeed, data, err) {
                        if (succeed) {
                            if (data.status) {
                                api.toast({
                                    msg: "操作成功",
                                    duration: 2000,
                                    location: 'bottom'
                                });
                                api.sendEvent({
                                    name: 'reloadmeetlist',
                                });
                                that.get_data();
                                return;
                            }
                            else if (data.Msg) {
                                api.toast({
                                    msg: data.Msg,
                                    duration: 2000,
                                    location: 'bottom'
                                });
                                return;
                            }
                        }
                        api.toast({
                            msg: err,
                            duration: 2000,
                            location: 'bottom'
                        });
                    });
                }
            });

        },
        //取消会议
        doMeetCancel() {
            var that = this;
            api.confirm({
                title: '提示',
                msg: '确定要取消会议预约吗?',
                buttons: ['确认', '取消']
            }, function (ret, err) {
                if (ret.buttonIndex == 1) {
                    ///调用接口
                    var options = {};
                    options.action = 'changemeetingreservation';
                    options.ID = that.ID;
                    options.ChangeType = 'cancelMeeting';
                    ns.post(options, function (succeed, data, err) {
                        if (succeed) {
                            if (data.status) {
                                api.toast({
                                    msg: "操作成功",
                                    duration: 2000,
                                    location: 'bottom'
                                });
                                api.sendEvent({
                                    name: 'reloadmeetlist',
                                });
                                that.get_data();
                                return;
                            }
                            else if (data.Msg) {
                                api.toast({
                                    msg: data.Msg,
                                    duration: 2000,
                                    location: 'bottom'
                                });
                                return;
                            }
                        }
                        api.toast({
                            msg: err,
                            duration: 2000,
                            location: 'bottom'
                        });
                    });
                }
            });
        },
    }
});
apiready = function () {
    api.parseTapmode();
    ns = window.Foresight.Util;
    dialog = new auiDialog();
    toast = new auiToast();

    app.ID = api.pageParam.ID || 0;
    if(app.ID){
        app.get_data();
    }
   
};
